# -*- coding: utf-8 -*-
"""
-------------------------------------------------
Project Name: luffcity study project
File Name: joinablequeue练习.py
Author: kij
Create Date: 2021/3/19
-------------------------------------------------
"""
from multiprocessing import Process, JoinableQueue
import time


def producter(q):
	for item in range(10):
		res = '包子%s' % item
		time.sleep(0.5)
		print('生产者生产%s' % res)
		q.put(res)
	q.join()


def consumer(q):
	while True:
		res = q.get()
		if res is None: break
		time.sleep(1)
		print("消费者%s" % res)
		q.task_done()


if __name__ == '__main__':
	q = JoinableQueue()

	# 创建生产者进程对象
	p1 = Process(target=producter, args=(q,))
	p2 = Process(target=producter, args=(q,))
	p3 = Process(target=producter, args=(q,))
	# 创建消费
	c1 = Process(target=consumer,args=(q,))
	c2 = Process(target=consumer,args=(q,))
	p1.start()
	p2.start()
	p3.start()
	c1.daemon = True
	c2.daemon = True
	c1.start()
	c2.start()
	p1.join()
	p2.join()
	p3.join()
	print('主')